package cn.wolfcode.p2p.bussness.service.impl;

import cn.wolfcode.p2p.base.util.Constants;
import cn.wolfcode.p2p.bussness.domain.SystemAccount;
import cn.wolfcode.p2p.bussness.domain.SystemAccountFlow;
import cn.wolfcode.p2p.bussness.mapper.SystemAccountFlowMapper;
import cn.wolfcode.p2p.bussness.service.ISystemAccountFlowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.Date;

@Service@Transactional
public class SystemAccountFlowServiceImpl implements ISystemAccountFlowService {
    @Autowired
    private SystemAccountFlowMapper systemAccountFlowMapper;

    private void createFlow(SystemAccount account, BigDecimal amount, int type, String note){
        SystemAccountFlow accountFlow = new SystemAccountFlow();
        accountFlow.setActionTime(new Date());
        accountFlow.setActionType(type);
        accountFlow.setAmount(amount);
        accountFlow.setFreezeAmount(account.getFreezedAmount());
        accountFlow.setUsableAmount(account.getUsableAmount());
        accountFlow.setNote(note);
        this.systemAccountFlowMapper.insert(accountFlow);
    }
    @Override
    public void createPayInterretManagerChargeFlow(SystemAccount systemAccount, BigDecimal amount) {
        createFlow(systemAccount,amount, Constants.SYSTEM_ACCOUNT_ACTIONTYPE_MANAGE_CHARGE,"收取用户借款手续费:"+amount+"元");

    }
}
